﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Administracija.DataLayer;

namespace Administracija.Repository
{
    public class RSablon : BaseRepository, InterfaceRepository<Sablon>
    {
        public IQueryable<Sablon> VratiSve()
        {
            dc = new AdministracijaDataContext();
            return dc.Sablons;
        }

        public Sablon Nov()
        {
            this.jeNov = true;

            Sablon n = new Sablon();
            n.BrojSablona = 1;

            n.Upit = @"-- ovde unesite upit

DECLARE @id INT
SET @id = {0}

-- Po potrebi ako se koriste detail podaci
-- DECLARE @d VARCHAR(MAX)
-- SELECT @d = COALESCE(@d,'') + kolona + CHAR(13) FROM Tabela WHERE Id = @id

SELECT *
FROM Tabela
WHERE Id = @id
";
            n.Naziv = "tekst";
            n.Status = true;
            n.DatumOd = DateTime.Now;

            return n;
        }

        public Sablon Izmeni(int id)
        {
            return dc.Sablons.SingleOrDefault(c => c.SablonId == id);
        }

        public int Snimi(Sablon t)
        {
            if (this.jeNov) dc.Sablons.InsertOnSubmit(t);
            dc.SubmitChanges();
            return t.SablonId;
        }

        public void Brisi(int id)
        {
            dc.Sablons.DeleteOnSubmit(dc.Sablons.SingleOrDefault(c => c.SablonId == id));
            dc.SubmitChanges();
        }
    }
}
